/*
 * @Author: 杨光辉(GerhardYang)
 * @Date: 2021-05-27 09:48:09
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-09-25 23:02:32
 * @Description: file content
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */
import Vue from "vue";
import App from "@/App.vue";
// vuex状态管理
import store from "@/store";
import localStorage from "@/utils/localStorage";
import axios from "axios";

axios.defaults.timeout = 30000;
// 获取配置信息存入vuex
function getSearchLayers() {
  return axios.get(
    window.getServiceUrl(
      "/jeecg-boot/SearchLayers/searchLayers/list",
      window.servicesPorts.boot
    )
  );
}

function getSearchLayersNodes() {
  return axios.get(
    window.getServiceUrl(
      "/jeecg-boot/SearchLayersNodes/searchLayersNodes/rootList",
      window.servicesPorts.boot
    )
  );
}

function getSearchDictionary() {
  return axios.get(
    window.getServiceUrl(
      "/jeecg-boot/SearchDictionary/searchDictionary/list",
      window.servicesPorts.boot
    ),
    {
      params: {
        pageSize: 1000,
      },
    }
  );
}

function getSearchMapoptions() {
  return axios.get(
    window.getServiceUrl(
      "/jeecg-boot/SearchMapoptions/searchMapoptions/list",
      window.servicesPorts.boot
    )
  );
}

function getSearchAreas() {
  return axios.get("./conf/searchAreas.json");
}
function getNetworkLayer() {
  return axios.get("./conf/networkLayer.json");
}
function getSceneLayer() {
  return axios.get("./conf/sceneLayer.json");
}
function getServerApis() {
  return axios.get("./conf/serverApis.json");
}

function getPoiLayer() {
  return axios.get("./conf/poiLayer.json");
}
function getStakesQlayers() {
  return axios.get("./conf/stakeQLayers.json");
}
function getmultiImageTypes() {
  return axios.get("./conf/multiImageType.json");
}
function getdefultLayers() {
  return axios.get("./conf/defultLayers.json");
}
function getstatisticdata() {
  return axios.get("./conf/statisticsData.json");
}
function getstatisticsFiledName() {
  return axios.get("./conf/statisticsFiledName.json");
}
function getqueryBackfileds() {
  return axios.get("./conf/queryBackfileds.json");
}
function getpoiCategory() {
  return axios.get("./conf/poiCategory.json");
}
// 多个请求现在都执行完成，加载配置参数存入locastorage
axios
  .all([
    getSearchLayers(),
    getSearchLayersNodes(),
    getSearchMapoptions(),
    getSearchDictionary(),
    getSearchAreas(),
    getNetworkLayer(),
    getSceneLayer(),
    getServerApis(),
    getPoiLayer(),
    getStakesQlayers(),
    getmultiImageTypes(),
    getdefultLayers(),
    getstatisticdata(),
    getstatisticsFiledName(),
    getqueryBackfileds(),
    getpoiCategory(),
  ])
  .then(
    axios.spread(function (
      SearchLayers_res,
      SearchLayersNodes_res,
      SearchMapoptions_res,
      SearchDictionary_res,
      SearchAreas_res,
      NetworkLayer_res,
      SceneLayer_res,
      ServerApis_res,
      PoiLayer_res,
      StakeQLayes_res,
      MultiImageTypes_res,
      defultLayers_res,
      statisticsdata_res,
      statisticsFiledName_res,
      queryBackfileds_res,
      poiCategory_res
    ) {
      //默认地图图层
      if (SearchLayers_res.status == 200) {
        const SearchLayers = SearchLayers_res.data.result.records;
        store.commit("setSearchLayers", SearchLayers);
      }
      //图层树
      if (SearchLayersNodes_res.status == 200) {
        const SearchLayersNodes = SearchLayersNodes_res.data.result.records;
        store.commit("setSearchLayersNodes", SearchLayersNodes);
      }
      //默认地图参数
      if (SearchMapoptions_res.status == 200) {
        const MapOptions = {};
        for (let item of SearchMapoptions_res.data.result.records) {
          MapOptions[item.name] = eval(item.value);
        }
        store.commit("setSearchMapoptions", MapOptions);
      }
      //字典表
      if (SearchDictionary_res.status == 200) {
        localStorage.set(
          "SearchDictionary",
          JSON.stringify(SearchDictionary_res.data.result.records)
        );
      }
      //区划面
      if (SearchAreas_res.status == 200) {
        let SearchAreas = SearchAreas_res.data.result.records;
        for (let i = 0; i < SearchAreas.length; i++) {
          SearchAreas[i].url = window.getServiceUrl(
            SearchAreas[i].url,
            window.servicesPorts.iserver
          );
        }
        store.commit("setSearchAreas", SearchAreas);
      }
      //多时相类型
      if (MultiImageTypes_res.status == 200) {
        let MultiImageTypes = MultiImageTypes_res.data.result.records;
        store.state.config.MultiImageTypes = MultiImageTypes;
        localStorage.set("MultiImageTypes", JSON.stringify(MultiImageTypes));
      }
      //poi分类
      if (poiCategory_res.status == 200) {
        let PoiCategory = poiCategory_res.data.result.records;
        store.state.config.PoiCategory = PoiCategory;
        localStorage.set("MultiImageTypes", JSON.stringify(PoiCategory));
      }

      //统计数据
      if (statisticsdata_res.status == 200) {
        let Statisticsdata = statisticsdata_res.data.result.records;
        store.state.config.Statisticsdata = Statisticsdata;
        localStorage.set("StatisticsData", JSON.stringify(Statisticsdata));
      }
      //返回字段
      if (queryBackfileds_res.status == 200) {
        let QueryBackfileds = queryBackfileds_res.data.result.records;
        store.state.config.QueryBackfileds = QueryBackfileds;
        localStorage.set("QueryBackfileds", JSON.stringify(QueryBackfileds));
      }

      //统计数据字段配置
      if (statisticsFiledName_res.status == 200) {
        let StatisticsFiledName = statisticsFiledName_res.data.result.records;
        store.state.config.StatisticsFiledName = StatisticsFiledName;
        localStorage.set(
          " StatisticsFiledName",
          JSON.stringify(StatisticsFiledName)
        );
      }

      if (defultLayers_res.status === 200) {
        let defultLayers = defultLayers_res.data.result.records;
        store.state.config.defultLayers = defultLayers;
        localStorage.set("defultLayers", JSON.stringify(defultLayers));
      }

      //网络分析
      if (NetworkLayer_res.status == 200) {
        let NetworkLayer = NetworkLayer_res.data.result.records;
        NetworkLayer.url = window.getServiceUrl(
          NetworkLayer.url,
          window.servicesPorts.iserver
        );
        store.state.config.NetworkLayer = NetworkLayer_res.data.result.records;
        localStorage.set(
          "NetworkLayer",
          JSON.stringify(NetworkLayer_res.data.result.records)
        );
      }
      //网络分析
      if (SceneLayer_res.status == 200) {
        let SceneLayer = SceneLayer_res.data.result.records;
        SceneLayer.url = window.getServiceUrl(
          SceneLayer.url,
          window.servicesPorts.iportal
        );
        store.state.config.SceneLayer = SceneLayer_res.data.result.records;
        localStorage.set(
          "SceneLayer",
          JSON.stringify(SceneLayer_res.data.result.records)
        );
      }

      if (ServerApis_res.status == 200) {
        let ServerApis = ServerApis_res.data.result.records;
        ServerApis.vehicleinfoServer.esurl = window.getServiceUrl(
          "",
          window.servicesPorts.es
        );
        store.state.config.ServerApis = ServerApis;
        localStorage.set(
          "ServerApis",
          JSON.stringify(ServerApis_res.data.result.records)
        );
      }
      if (PoiLayer_res.status == 200) {
        let PoiLayer = PoiLayer_res.data.result.records;
        PoiLayer.dataurl = window.getServiceUrl(
          PoiLayer.dataurl,
          window.servicesPorts.iserver
        );
        store.state.config.PoiLayer = PoiLayer_res.data.result.records;
        localStorage.set(
          "PoiLayer",
          JSON.stringify(PoiLayer_res.data.result.records)
        );
      }
      if (StakeQLayes_res.status == 200) {
        let StakeQLayes = StakeQLayes_res.data.result.records;
        for (let i = 0; i < StakeQLayes.length; i++) {
          StakeQLayes[i].host = window.getServiceUrl(
            "",
            window.servicesPorts.iserver
          );
          StakeQLayes[i].stakelayer.dataurl = window.getServiceUrl(
            StakeQLayes[i].stakelayer.dataurl,
            window.servicesPorts.iserver
          );
          StakeQLayes[i].roadlayer.dataurl = window.getServiceUrl(
            StakeQLayes[i].roadlayer.dataurl,
            window.servicesPorts.iserver
          );
          // StakeQLayes[i].roadlayer.dataurl=StakeQLayes[i].host+StakeQLayes[i].roadlayer.dataurl
          // StakeQLayes[i].stakelayer.dataurl=StakeQLayes[i].host+StakeQLayes[i].stakelayer.dataurl
        }
        store.state.config.StakeQLayes = StakeQLayes_res.data.result.records;
        localStorage.set(
          "StakeQLayes",
          JSON.stringify(StakeQLayes_res.data.result.records)
        );
      }

      new Vue({
        store,
        render: (h) => h(App),
      }).$mount("#app");
    })
  )
  .catch((err) => {
    console.log(err.response);
    alert("系统配置文件加载错误，请联系管理员！");
  });
